import Page
from Page import Personal
from Base.Base import Base
from selenium.webdriver.common.by import By


class PersonalCarnumber(Base):
    """
     车牌号页面
    """

    # TODO:车牌号滑动页面没有编写

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.carnumber_home_btn = (By.XPATH, Personal.RESOURCE_ID.format("ivHome"))

        # 左侧的返回键
        self.carnumber_back_btn = (By.XPATH, Personal.RESOURCE_ID.format('ivBack'))

        # 页面_变量名_元素类型
        # 车牌号标签名称
        self.carnumber_car_title_text = (By.XPATH, Personal.RESOURCE_ID.format("tv_title"))

        # 车牌号输入框
        self.carnumber_car_number_input = (By.XPATH, Personal.RESOURCE_ID.format(("plate_number")))

        # 车牌号确认按钮
        self.carnumber_ok_btn = (By.XPATH, Personal.RESOURCE_ID.format("tv_sure"))

        # 车牌号取消按钮
        self.carnumber_no_btn = (By.XPATH, Personal.RESOURCE_ID.format("tv_cancel"))

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.carnumber_home_btn)

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.carnumber_back_btn)

    def get_car_title(self):
        """
        获取车牌号弹窗标题

        :return: 获取元素
        """
        return self.find_element_o(self.carnumber_car_title_text)

    def input_car_number(self, text=12345):
        """
        车牌号输入框

        :param text: 输入车牌号
        :return:
        """
        self.input_text(self.carnumber_car_number_input, text)

    def click_car_ok(self):
        """
        点击车牌号确认按钮

        :return: None
        """
        self.click_element(self.carnumber_ok_btn)

    def click_car_no(self):
        """
        点击车牌号取消按钮

        :return: None
        """
        self.click_element(self.carnumber_no_btn)

    def swipe_car_number_info1_text(self, direction=Page.DIRECTION_UP):
        """
        滑动车牌中文

        :param direction: 滑动方向, 默认向上滑
        :return:
        """
        self.swipe_o(location=(720, 720, 350, 300), direction=direction)

    def is_display_personal_car_number(self):
        """
        是否存在车牌号码界面

        :return: bool
        """
        return self.is_display(self.carnumber_car_title_text)
